package com.hl.service;


import com.github.pagehelper.PageHelper;
import com.hl.domain.Heartknowledge;
import com.hl.mapper.HeartknowledgeMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class HeartknowledgeService {

    @Autowired
    private HeartknowledgeMapper heartknowledgeMapper;

    //插入一条知识信息
    public int insertOne(Heartknowledge heartknowledge ){
        return heartknowledgeMapper.insert(heartknowledge);
    }

    //查找所有信息
    public List<Heartknowledge> heartknowledgeList(int pageNum,int pageSize){
        PageHelper.startPage(pageNum,pageSize);
        return heartknowledgeMapper.HEARTKNOWLEDGE_LIST();
    }

    //根据标题名字查找
    public List<Heartknowledge> selectByName(String name,int pageNum,int pageSize,  Date startTime, Date endTime){
        PageHelper.startPage(pageNum,pageSize);
        return heartknowledgeMapper.selectByName(name,startTime,endTime);
    }

    //根据id删除数据
    public int deleteById(long id){
        return heartknowledgeMapper.deleteByPrimaryKey(id);
    }

    //根据id更新数据
    public int updateById(Heartknowledge heartknowledge){
        heartknowledge.setCreatetime(new Date());
        return heartknowledgeMapper.updateByPrimaryKey(heartknowledge);
    }

    //根据id查找信息
    public Heartknowledge selectOne(long id){
        return heartknowledgeMapper.selectByPrimaryKey(id);
    }

    //根据id查找text
    public String selectText(long id){
        return heartknowledgeMapper.selectText(id);
    }

//     查询所有心理健康的文章
    public List<Heartknowledge> getAllList()
    {
        return heartknowledgeMapper.getAllHeartknowledge();
    }
}
